package com.wenlin.userservice.controller;

import com.wenlin.userservice.domain.MethodLock;
import com.wenlin.userservice.lock.MyLog;
import com.wenlin.userservice.mapper.MethodLockMapper;
import com.wenlin.userservice.service.MethodService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 *  Created with IntelliJ IDEA.
 *  Author:  wenlin
 *  Date:  2018/3/29 10:46
 *  Description:
 **/
@RestController
@RequestMapping("/user/rest")
@Api(description = "测试")
public class JsonRest {

    @Autowired
    private MethodLockMapper methodLockMapper;
    @Autowired
    private MethodService methodService;
    //获取数据
    @GetMapping("/db")
    public MethodLock getLog() throws InterruptedException {
          Long time1 = System.currentTimeMillis();
          MethodLock   methodLock = methodLockMapper.selectByPrimaryKey(1);
          Long time2 = System.currentTimeMillis();
          Long time = time2-time1;
          methodLock.setTime(time);
          return  methodLock;
    }
    @GetMapping("/db2")
    public MethodLock getLock() throws InterruptedException {

        MethodLock  methodLock = methodService.getLcok(1);

        return  methodLock;
    }
}
